<?php
class Group extends CActiveRecord
{
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	public function tableName()
	{
		return '{{group}}';
	}

	public function rules()
	{
		return array(
			array('name,description,category,image','required'),
		);
	}

	public function relations()
	{
		return array(
			'topics'=>array(self::HAS_MANY,'Topic','gid'),
			'members'=>array(self::MANY_MANY,'User','{{user_group}}(gid,uid)'),
			'admin'=>array(self::BELONGS_TO,'User','admin_id'),
		);
	}

	public function beforeSave()
	{
		if(parent::beforeSave())
		{
			if($this->isNewRecord)
			{
				$this->created=new CDbExpression('now()');
			}
			$this->description=nl2br($this->description);
		}
		return true;
	}
}
?>
